/*
Web: http://www.jsForms.com
Copyright (C) 2008  Igor Demyanov (mailto:Igor.Demyanov@gmail.com)
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
jsForms.Templates["common.ButtonDiv"]='<div class="ButtonDiv"/>';
jsForms.Components["common.ButtonDiv"]={
	Init: function()
	{
		return this.SetEnable(true);
	},
	SetEnable: function(flag)
	{
		if (this.P.Enabled != flag) {
			this.P.Enabled = flag==true;
			//console.log(this._Name + ':Button.SetEnable(' + flag + ')');
			this.attr('state', flag ? 'enabled' : 'disabled');
			if (flag) {
					this.unbind('click').bind('click',this,this.eventClick );
			}
			else {
				this.unbind('click');
			}
		}
		return this;
	},
	GetEnable:function()
	{
		//console.log(this._Name+':Button.GetEnable');
		return this.P.Enabled;
	},
	eventClick : function(e)
	{
		if (e.data) {
			if (e.data.P.Enabled) {
				e.data._ExecEvent('onClick');
			}
		}
	}
};
jsForms.CreateCompileInfoByObject(
{
	Name: 'common.ButtonDiv',
	Properties: {
		Enable: {
			Type: 'Boolean',
			Access: 'GETSET'
		}
	},
	Events: {
		onClick: {}
	}
});

jsForms.Components["common.Button"] = {
	Init: function()
	{
		return this.SetEnabled(true);
	},
	eventClick : function(e)
	{
		if (e.data) {
			if (e.data.P.Enabled) {
				e.data._ExecEvent('onClick');
			}
		}
	},
	SetEnabled: function(flag)
	{
		if (this.P.Enabled != flag) {
			this.P.Enabled = flag==true;
			this.attr('state', flag ? 'enabled' : 'disabled');
			if (flag) {
					this.unbind('click').bind('click',this,this.eventClick );
			}
			else {
				this.unbind('click');
			}
		}
		return this;
	},
	GetEnabled:function()
	{
		return this.P.Enabled;
	},
	GetText: function()
	{
		return this.P.text;
	},
	SetText: function(newText)
	{
		if (this.P.text != newText) {
			this.P.text = newText;
			this.C.text[0].innerHTML = newText;
		}
		return this;
	}
};
// -----------------------------------------------
// Compilation INFO
// -----------------------------------------------
jsForms.CreateCompileInfoByObject(
{
	Name: 'common.Button',
	Properties: {
		Enabled: {
			Type: 'Boolean',
			Access: 'GETSET'
		},
		Text: {}
	},
	Events: {
		onClick: {}
	}
});
// -----------------------------------------------
